/*  完美立方 */

#include<iostream>
#include<algorithm>
using namespace std;

int main(void)
{
	int N = 24;
	int a, b, c, d;

	int *pCube = new int[N + 1];	//0 ~ N - 1, total N numbers
	generate(pCube, pCube + N + 1, [](void) -> int {static int i = 0; int temp = i++; return temp * temp * temp;});


	for (a = 4; a <= N; a++)
	{
		for (int b = 2; b < a; b++)
		{
			if (3 * pCube[b] > pCube[a])
			{
				break;
			}

			for (int c = b; c < a; c++)
			{
				if (pCube[b] + 2 * pCube[c] > pCube[a])
				{
					break;
				}

				for (int d = c; d < a; d++)
				{
					int res = pCube[b] + pCube[c] + pCube[d];

					if (res >= pCube[a])
					{
						if (res == pCube[a])
						{
							cout<< a << "^3 = " << b << "^3 + " << c <<"^3 + " << d << "^3 " <<endl;
						}

						break;
					}
				}
			}
		}
	}


	delete[] pCube;
	return 0;
}
